{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bs4 import BeautifulSoup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "doc = BeautifulSoup(open('metadata'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "trs = doc.find_all('tr')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Matching the Blanks\n",
      "https://arxiv.org/abs/1906.03158\n",
      "\n",
      "Google Research\n",
      "(Feb 26, 2019)\n",
      "['93.86', '97.06', '89.20', '94.27']\n",
      "---\n",
      "Anonymous Groundhog\n",
      "\n",
      "\n",
      "\n",
      "(Nov 3, 2019)\n",
      "['90.31', '94.28', '85.48', '90.51']\n",
      "---\n",
      "Anonymous Pony\n",
      "\n",
      "\n",
      "\n",
      "(Jan 17, 2020)\n",
      "['91.61', '96.01', '86.78', '91.63']\n",
      "---\n",
      "Anonymous Python\n",
      "\n",
      "\n",
      "\n",
      "(Nov 3, 2019)\n",
      "['88.30', '95.94', '81.10', '92.67']\n",
      "---\n",
      "BERT-PAIR\n",
      "https://www.aclweb.org/anthology/D19-1649.pdf\n",
      "https://github.com/thunlp/fewrel\n",
      "THUNLP, Tsinghua University\n",
      "(Nov 3, 2019)\n",
      "['88.32', '93.22', '80.63', '87.02']\n",
      "---\n",
      "MLMAN\n",
      "https://arxiv.org/abs/1906.06678\n",
      "https://github.com/ZhixiuYe/MLMAN\n",
      "NEL-SLIP, University of Science and Technology of China\n",
      "(Jan 10, 2019)\n",
      "['82.98', '92.66', '73.59', '87.29']\n",
      "---\n",
      "PLATO\n",
      "\n",
      "\n",
      "Primer.ai\n",
      "(Nov 19, 2019)\n",
      "['82.93', '91.76', '74.41', '85.91']\n",
      "---\n",
      "Prototypical Network (LM-Transformer)\n",
      "\n",
      "\n",
      "LAVIS, University of Applied Sciences RheinMain\n",
      "(Jan 18, 2019)\n",
      "['81.40', '92.11', '72.51', '86.03']\n",
      "---\n",
      "TDCN\n",
      "\n",
      "\n",
      "Anonymous\n",
      "(Jul 23, 2019)\n",
      "['81.93', '92.08', '72.18', '85.98']\n",
      "---\n",
      "LM-ProtoNet (FGM)\n",
      "\n",
      "\n",
      "Anonymous\n",
      "(Feb 15, 2019)\n",
      "['76.60', '89.31', '65.31', '82.10']\n",
      "---\n",
      "Prototypical Network (CNN)\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "['74.52', '88.40', '62.38', '80.45']\n",
      "---\n",
      "SNAIL (CNN)\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "['67.29', '79.40', '53.28', '68.33']\n",
      "---\n",
      "GNN (CNN)\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "['66.23', '81.28', '46.27', '64.02']\n",
      "---\n",
      "Meta Network (CNN)\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "['64.46', '80.57', '53.96', '69.23']\n",
      "---\n",
      "kNN (PCNN)\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "['60.28', '72.41', '46.15', '59.11']\n",
      "---\n",
      "kNN (CNN)\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "['54.67', '68.77', '41.24', '55.87']\n",
      "---\n",
      "Finetune (CNN)\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "['44.21', '68.66', '27.30', '55.04']\n",
      "---\n",
      "Finetune (PCNN)\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "['45.64', '57.86', '29.65', '37.43']\n",
      "---\n"
     ]
    }
   ],
   "source": [
    "metafile = open('meta.csv', 'w')\n",
    "for tr in trs:\n",
    "    tds = tr.find_all('td')\n",
    "    assert(len(tds) == 5)\n",
    "    meta = tds[0]\n",
    "    name = meta.get_text().split('\\n')[0].strip()\n",
    "    if len(name) == 0:\n",
    "        name = meta.get_text().split('\\n')[1].strip()\n",
    "    print(name)\n",
    "    hrefs = tr.find_all('a')\n",
    "    paper = ''\n",
    "    code = ''\n",
    "    for href in hrefs:\n",
    "        if href.get_text() == '[paper]':\n",
    "            paper = href['href']\n",
    "        elif href.get_text() == '[code]':\n",
    "            code = href['href']\n",
    "        else:\n",
    "            raise Exception('Unknown href')\n",
    "    print(paper)\n",
    "    print(code)\n",
    "    strongs = tr.find_all('strong')\n",
    "    inst = ''\n",
    "    if len(strongs) > 0:\n",
    "        inst = strongs[0].get_text()\n",
    "    print(inst)\n",
    "    \n",
    "    try:\n",
    "        date = meta.get_text().split('\\n')[-2].strip()\n",
    "    except:\n",
    "        date = ''\n",
    "    print(date)\n",
    "    \n",
    "    pf = [tds[1].get_text(), tds[2].get_text(), tds[3].get_text(), tds[4].get_text()]\n",
    "    print(pf)\n",
    "    \n",
    "    print('---')\n",
    "    \n",
    "    metafile.write(\"{}\\t{}\\t{}\\t{}\\t{}\\t{}\\t{}\\t{}\\t{}\\n\".format(name, paper, code, inst, date, pf[0], pf[1], pf[2], pf[3]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "metafile.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
